﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufBase.h"
#include "GnufImpl.h"
#include "GnufComponent.h"
#include "GnufItemEvents.h"
#include "GnufModuleManager.h"

namespace gnuf {
    class DropDownBoard;
    class CheckButton;
    class Block;

    struct GNUF_BASE_EXPORT MainToolbarStyleOptions
    {
        bool showBigIcon        = true; // true: showBigIcon,       false: showSmallIcon
        bool showCaption        = true; // true: showCaption,       false: hideCaption
        bool showBlockCaption   = true; // true: showBlockCaption,  false: hideBlockCaption
        bool alignCenter        = true; // true: alignCenter,       false: alignLeft

        bool operator==(const MainToolbarStyleOptions &) const;
    };

    namespace impl { class GNUF_IMPL_CLASS(MainToolbar); }
    class GNUF_BASE_EXPORT MainToolbar final
    {
        GNUF_IMPL_USE(MainToolbar);
    public:
        MainToolbar(const std::wstring & key, const std::wstring & config, bool file = true);
        ~MainToolbar();
        static MainToolbar * get();
        void setBreadscrumb(const std::wstring &);
        void setWorkspaceSelected(const std::wstring & workspace);
        const std::wstring & getCurrentWorkspce() const;
        const gcmp::UniqueString* uniqueKey() const;
        const Block * blockByCaption(const std::wstring &) const;
        
        /// \brief Set the style options.
        static void setStyleOptions(const MainToolbarStyleOptions &);
        /// \return Return the style options.
        static const MainToolbarStyleOptions & styleOptions();
    };
}

namespace gnuf { namespace impl {
    class MainToolbarImpl final
        : public Component
        , public IItemEventHandler
    {
        GNUF_IMPL_USED_BY(MainToolbar);
    public:
        MainToolbarImpl(MainToolbar * pMtb,
            const std::wstring & key, const std::wstring & config, bool byFile);
        ~MainToolbarImpl();

        void setBreadscrumb(const std::wstring &);
        void setWorkspaceSelected(const std::wstring & workspace);

        const Block * blockByCaption(const std::wstring &) const;
        
        void apply(const MainToolbarStyleOptions &);
        bool isVisibleSibling() const { return m_visibleSibling; }

    protected:
        // Inherits from ArrangementAreaContent...
        virtual void onPostConnectedWithArrangementArea() override;
        virtual void onPreDisconnectedFromArrangementArea() override;

        // Inherits from Component...
        virtual void initialize(Toolbar *) override;
        virtual gcmp::OwnerPtr<QtToolbar> createQtToolBar(Toolbar*) override;
        virtual void onPostToolbarCreated() override;
        virtual bool hasSiblings(Component::Ones *) const override;
        virtual void onPostSiblingVisibilityChanged(const bool visible) override;
        virtual ETransferingContentMethod decideTransferringContentMethod(
            const Item * pSender, const Item * pAcceptor, const Item * pContent) const override;
        virtual void onPostDumpFromConfigString() override;
        virtual void onEvent(ArrangementAreaEvent*) override;

        // Inherits from IItemEventHandler...
        virtual void onHovered(Item *, bool, void *) override;
        virtual bool onPreClicked(Item *) override;
        virtual void onCheckStatusChanged(CheckButton*) override;
        virtual void onHeightChanged(Toolbar *, int) override;
        virtual void onQtMousePressed(Toolbar *, void *) override;
        virtual bool onAllowToShow(Item *) const override;
        virtual void onContentChanged(Item *, const IItemEventHandler::ContentChange &) override;

    private:
        bool doesAllowToShow(const Block &) const;

        gcmp::OwnerPtr< DropDownBoard > m_contextMenu;
        std::wstring m_currWorkspace;
        bool m_visibleSibling = false;
    };
} }
